﻿using System;
using System.Collections.Generic;
//using System.Drawing;
using System.Text;
using System.Xml.Serialization;
using VMS.FTS.APPPUSH.Log;
using VMS.FTS.APPPUSH.VmsCenter;

namespace VMS.FTS.APPPUSH.Device
{
    /// <summary>
    ///  Base class for device status
    /// </summary>
    public class VMSDeviceStatus_local {
        // network status: connected or not
        [XmlElement("Network",DataType="boolean")]
        public Boolean Connected { get; set; }
        // Sensors status
        [XmlIgnore]
        public List<VMSSensor> Sensors { get; set; }
        // Sd-card status
        [XmlIgnore]
        public VMSMemoryInfo MemoryInfo { get; set; }
        // Current data on screen
        [XmlIgnore]
        public byte[] ScreenData { get; set; }
    }

    /// <summary>
    /// Base class for device info
    /// </summary>
    public class VMSDeviceInfo_local {
        // VMS Name
        [XmlElement("Name")]
        public string Name;// { get; set; }
        // VMS Longtitude
        [XmlElement("Longitude", DataType = "double")]
        public Double Longitude  { get; set; }

        // VMS Latitude
        [XmlElement("Latitude", DataType = "double")]
        public Double Latitude { get; set; }
        // VMS Type
        [XmlElement("Type")]
        public string Type { get; set; }
        // VMS Firmware version
        [XmlElement("Firmware",DataType="int")]

        public Int32 FirmwareVersion { get; set; }
    }

    // Base class for VMS devices
    [Serializable]
    //[XmlInclude(typeof(LETI))]
    [XmlRoot("VMSDevice")]
    public abstract class VMSDevice : ILogable
    {
        [XmlAttributeAttribute(AttributeName = "ID")]
        public string ID { get; set; } 

        [XmlAttributeAttribute(AttributeName = "IMEI")]
        public string IMEI { get; set; } 

        [XmlElement("VMSInfo")]
        public VmsDeviceInfo Info { get; set; }  

        [XmlElement("VMSStatus")]
        public VmsDeviceStatus Status { get; set; }

        

        /* 
         * Constructors 
        **/
        /// <summary>
        /// Default Constructor
        /// </summary>
        /// <returns></returns>
        public VMSDevice()
        {
            LOG_TAG = this.GetType().Name;
            Status = new VmsDeviceStatus();
            Info = new VmsDeviceInfo();
        }

        /// <summary>
        /// Constructor
        /// </summary>
        /// <param name="stt">Device's status</param>
        /// <param name="info">Device's info</param>
        public VMSDevice(VmsDeviceStatus stt,VmsDeviceInfo info)
        {
            Status = stt;
            Info = info;
        }

        /// <summary>
        /// Constructor
        /// </summary>
        /// <param name="stt">Device's status</param>
        /// <param name="info">Device's info</param>
        public VMSDevice(VMSDevice other)
        {
            ID = other.ID;
            IMEI = other.IMEI;

            Status = other.Status;
            Info = other.Info;
        }

        /// <summary>
        /// Abstract interface to close device
        /// </summary>
        public abstract void close();

        /// <summary>
        /// Abstract inferface to open device
        /// </summary>
        /// <param name="o"></param>
        public abstract void open(Object o);

        /// <summary>
        /// abstract function to process command
        /// </summary>
        /// <param name="command"></param>
        /// <returns></returns>
        /// <exception cref="VMSLayoutNotFoundException"/>
        public abstract bool ProcessCommand(VmsCenter.VmsCommand command);

        public abstract bool UpdateDeviceStatus();
    }

    public class VMSLayoutNotFoundException : Exception
    {
        public int LayoutID = -1;// Unknow
        public VMSLayoutNotFoundException()
            : base()
        {
            LayoutID = -1;
        }

        public VMSLayoutNotFoundException(int layoutID)    
        {

            LayoutID = layoutID;
        }


    }
}
